package task3.combo;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.beans.PropertyEditor;

public class OperationEditor implements PropertyEditor {
	private PropertyChangeSupport _support;
	private Integer _value;

	public OperationEditor() {
		this._support = new PropertyChangeSupport(this);
	}

	public String getAsText() {
		return String.valueOf(this._value);
	}

	public Component getCustomEditor() {
		return null;
	}

	public String getJavaInitializationString() {
		return String.valueOf(this._value);
	}

	public String[] getTags() {
		String[] tags = { "AND", "OR", "XOR" };

		return tags;
	}

	public Object getValue() {
		return this._value;
	}

	public boolean isPaintable() {
		return false;
	}

	public void paintValue(Graphics arg0, Rectangle arg1) {
	}

	public void setAsText(String text) throws IllegalArgumentException {
		if (text.equals("AND")) {
			this._value = Integer.valueOf(0);
		} else if (text.equals("OR")) {
			this._value = Integer.valueOf(1);
		} else if (text.equals("XOR")) {
			this._value = Integer.valueOf(2);
		}
		this._support.firePropertyChange("", null, null);
	}

	public void setValue(Object value) {
		this._value = ((Integer) value);
	}

	public boolean supportsCustomEditor() {
		return false;
	}

	public void addPropertyChangeListener(PropertyChangeListener listener) {
		this._support.addPropertyChangeListener(listener);
	}

	public void removePropertyChangeListener(PropertyChangeListener listener) {
		this._support.removePropertyChangeListener(listener);
	}
}
